home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Information / Languages / C++ / C++ FAQ 4⁄4 < prev   
Encoding:
Text File  |  1994-12-08  |  28.6 KB  |  746 lines  |  [TEXT/R*ch]

  1. Path: bloom-beacon.mit.edu!gatech!howland.reston.ans.net!pipex!uunet!library.erc.clarkson.edu!sun.soe.clarkson.edu!cline
  2. From: cline@sun.soe.clarkson.edu (Marshall Cline)
  3. Newsgroups: comp.lang.c++
  4. Subject: C++ FAQ: posting #4/4
  5. Followup-To: comp.lang.c++
  6. Date: 14 Nov 1994 00:26:49 GMT
  7. Organization: Paradigm Shift, Inc (training/consulting/OOD/OOP/C++)
  8. Lines: 729
  9. Sender: cline@sun.soe.clarkson.edu
  10. Distribution: world
  11. Expires: +1 month
  12. Message-ID: <3a6as9$gd9@library.erc.clarkson.edu>
  13. Reply-To: cline@parashift.com (Marshall Cline)
  14. NNTP-Posting-Host: sun.soe.clarkson.edu
  15. Summary: Please read this before posting to comp.lang.c++
  16.  
  17. comp.lang.c++ Frequently Asked Questions list (with answers, fortunately).
  18. Copyright (C) 1991-94 Marshall P. Cline, Ph.D.
  19. Posting 4 of 4.
  20. Posting #1 explains copying permissions, (no)warranty, table-of-contents, etc
  21.  
  22. ==============================================================================
  23. SECTION 17: Linkage-to/relationship-with C
  24. ==============================================================================
  25.  
  26. Q98: How can I call a C function "f(int,char,float)" from C++ code?
  27.  
  28. Tell the C++ compiler that it is a C function:
  29.     extern "C" void f(int,char,float);
  30.  
  31. Be sure to include the full function prototype.  A block of many C functions
  32. can be grouped via braces, as in:
  33.  
  34.     extern "C" {
  35.       void* malloc(size_t);
  36.       char* strcpy(char* dest, const char* src);
  37.       int   printf(const char* fmt, ...);
  38.     }
  39.  
  40. ==============================================================================
  41.  
  42. Q99: How can I create a C++ function "f(int,char,float)" that is callable by
  43.    my C code?
  44.  
  45. The C++ compiler must know that "f(int,char,float)" is to be called by a C
  46. compiler using the same "extern C" construct detailed in the previous FAQ.
  47. Then you define the function in your C++ module:
  48.  
  49.     void f(int x, char y, float z)
  50.     {
  51.       //...
  52.     }
  53.  
  54. The "extern C" line tells the compiler that the external information sent to
  55. the linker should use C calling conventions and name mangling (e.g., preceded
  56. by a single underscore).  Since name overloading isn't supported by C, you
  57. can't make several overloaded fns simultaneously callable by a C program.
  58.  
  59. Caveats and implementation dependencies:
  60.  * your "main()" should be compiled with your C++ compiler (for static init).
  61.  * your C++ compiler should direct the linking process (for special libraries).
  62.  * your C and C++ compilers may need to from same vendor (calling convention).
  63.  
  64. ==============================================================================
  65.  
  66. Q100: Why's the linker giving errors for C/C++ fns being called from C++/C
  67.    fns?
  68.  
  69. See the previous two FAQs on how to use "extern "C"."
  70.  
  71. ==============================================================================
  72.  
  73. Q101: How can I pass an object of a C++ class to/from a C function?
  74.  
  75. Here's an example:
  76.  
  77.     /****** C/C++ header file: Fred.h ******/
  78.     #ifdef __cplusplus    /*"__cplusplus" is #defined if/only-if compiler is C++*/
  79.       extern "C" {
  80.     #endif
  81.  
  82.     #ifdef __STDC__
  83.       extern void c_fn(struct Fred*);    /* ANSI-C prototypes */
  84.       extern struct Fred* cplusplus_callback_fn(struct Fred*);
  85.     #else
  86.       extern void c_fn();            /* K&R style */
  87.       extern struct Fred* cplusplus_callback_fn();
  88.     #endif
  89.  
  90.     #ifdef __cplusplus
  91.       }
  92.     #endif
  93.  
  94.     #ifdef __cplusplus
  95.       class Fred {
  96.       public:
  97.         Fred();
  98.         void wilma(int);
  99.       private:
  100.         int a_;
  101.       };
  102.     #endif
  103.  
  104. "Fred.C" would be a C++ module:
  105.  
  106.     #include "Fred.h"
  107.     Fred::Fred() : a_(0) { }
  108.     void Fred::wilma(int a) : a_(a) { }
  109.  
  110.     Fred* cplusplus_callback_fn(Fred* fred)
  111.     {
  112.       fred->wilma(123);
  113.       return fred;
  114.     }
  115.  
  116. "main.C" would be a C++ module:
  117.  
  118.     #include "Fred.h"
  119.  
  120.     int main()
  121.     {
  122.       Fred fred;
  123.       c_fn(&fred);
  124.       return 0;
  125.     }
  126.  
  127. "c-fn.c" would be a C module:
  128.  
  129.     #include "Fred.h"
  130.     void c_fn(struct Fred* fred)
  131.     {
  132.       cplusplus_callback_fn(fred);
  133.     }
  134.  
  135. Passing ptrs to C++ objects to/from C fns will FAIL if you pass and get back
  136. something that isn't EXACTLY the same pointer.  For example, DON'T pass a base
  137. class ptr and receive back a derived class ptr, since your C compiler won't
  138. understand the pointer conversions necessary to handle multiple and/or virtual
  139. inheritance.
  140.  
  141. ==============================================================================
  142.  
  143. Q102: Can my C function access data in an object of a C++ class?
  144.  
  145. Sometimes.
  146.  
  147. (First read the previous FAQ on passing C++ objects to/from C functions.)
  148.  
  149. You can safely access a C++ object's data from a C function if the C++ class:
  150.  * has no virtual functions (including inherited virtual fns)
  151.  * has all its data in the same access-level section (private/protected/public)
  152.  * has no fully-contained subobjects with virtual fns
  153.  
  154. If the C++ class has any base classes at all (or if any fully contained
  155. subobjects have base classes), accessing the data will TECHNICALLY be
  156. non-portable, since class layout under inheritance isn't imposed by the
  157. language.  However in practice, all C++ compilers do it the same way: the base
  158. class object appears first (in left-to-right order in the event of multiple
  159. inheritance), and subobjects follow.
  160.  
  161. Furthermore, if the class (or any base class) contains any virtual functions,
  162. you can often (but less than always) assume a "void*" appears in the object
  163. either at the location of the first virtual function or as the first word in
  164. the object.  Again, this is not required by the language, but it is the way
  165. "everyone" does it.
  166.  
  167. If the class has any virtual base classes, it is even more complicated and less
  168. portable.  One common implementation technique is for objects to contain an
  169. object of the virtual base class (V) last (regardless of where "V" shows up as
  170. a virtual base class in the inheritance hierarchy).  The rest of the object's
  171. parts appear in the normal order.  Every derived class that has V as a virtual
  172. base class actually has a POINTER to the V part of the final object.
  173.  
  174. ==============================================================================
  175.  
  176. Q103: Why do I feel like I'm "further from the machine" in C++ as opposed to
  177.    C?
  178.  
  179. Because you are.
  180.  
  181. As an OOPL, C++ allows you to model the problem domain itself, which allows you
  182. to program in the language of the problem domain rather than in the language of
  183. the solution domain.
  184.  
  185. One of C's great strengths is the fact that it has "no hidden mechanism": what
  186. you see is what you get.  You can read a C program and "see" every clock cycle.
  187. This is not the case in C++; old line C programmers (such as many of us once
  188. were) are often ambivalent (can anyone say, "hostile") about this feature, but
  189. they soon realize that it provides a level of abstraction and economy of
  190. expression which lowers maintenance costs without destroying run-time
  191. performance.
  192.  
  193. Naturally you can write bad code in any language; C++ doesn't guarantee any
  194. particular level of quality, reusability, abstraction, or any other measure of
  195. "goodness."  C++ doesn't try to make it impossible for bad programmers to write
  196. bad programs; it enables reasonable developers to create superior software.
  197.  
  198. ==============================================================================
  199. SECTION 18: Pointers to member functions
  200. ==============================================================================
  201.  
  202. Q104: Is the type of "ptr-to-member-fn" different from "ptr-to-fn"?
  203.  
  204. Yep.
  205.  
  206. Consider the following function:
  207.  
  208.     int f(char a, float b);
  209.  
  210. If this is an ordinary function, its type is:    int (*)      (char,float);
  211. If this is a method of class Fred, its type is:  int (Fred::*)(char,float);
  212.  
  213. ==============================================================================
  214.  
  215. Q105: How can I ensure objects of my class are always created via "new" rather
  216.    than as locals or global/static objects?
  217.  
  218. Make sure the class's constructors are "private:", and define "friend" or
  219. "static" fns that return a ptr to the objects created via "new" (make the
  220. constructors "protected:" if you want to allow derived classes).
  221.  
  222.     class Fred {    //only want to allow dynamicly allocated Fred's
  223.     public:
  224.       static Fred* create()                 { return new Fred();     }
  225.       static Fred* create(int i)            { return new Fred(i);    }
  226.       static Fred* create(const Fred& fred) { return new Fred(fred); }
  227.     private:
  228.       Fred();
  229.       Fred(int i);
  230.       Fred(const Fred& fred);
  231.       virtual ~Fred();
  232.     };
  233.  
  234.     main()
  235.     {
  236.       Fred* p = Fred::create(5);
  237.       ...
  238.       delete p;
  239.     }
  240.  
  241. ==============================================================================
  242.  
  243. Q106: How do I pass a ptr to member fn to a signal handler, X event callback,
  244.    etc?
  245.  
  246. Don't.
  247.  
  248. Because a member function is meaningless without an object to invoke it on, you
  249. can't do this directly (if The X Windows System was rewritten in C++, it would
  250. probably pass references to OBJECTS around, not just pointers to fns; naturally
  251. the objects would embody the required function and probably a whole lot more).
  252.  
  253. As a patch for existing software, use a top-level (non-member) function as a
  254. wrapper which takes an object obtained through some other technique (held in a
  255. global, perhaps).  The top-level function would apply the desired member
  256. function against the global object.
  257.  
  258. E.g., suppose you want to call Fred::memfn() on interrupt:
  259.  
  260.     class Fred {
  261.     public:
  262.       void memfn();
  263.       static void staticmemfn();    //a static member fn can handle it
  264.       //...
  265.     };
  266.  
  267.     //wrapper fn remembers the object on which to invoke memfn in a global:
  268.     Fred* object_which_will_handle_signal;
  269.     void Fred_memfn_wrapper() { object_which_will_handle_signal->memfn(); }
  270.  
  271.     main()
  272.     {
  273.       /* signal(SIGINT, Fred::memfn); */   //Can NOT do this
  274.       signal(SIGINT, Fred_memfn_wrapper);  //Ok
  275.       signal(SIGINT, Fred::staticmemfn);   //Also Ok
  276.     }
  277.  
  278. Note: static member functions do not require an actual object to be invoked, so
  279. ptrs-to-static-member-fns are type compatible with regular ptrs-to-fns (see ARM
  280. p.25, 158).
  281.  
  282. ==============================================================================
  283.  
  284. Q107: Why am I having trouble taking the address of a C++ function?
  285.  
  286. This is a corollary to the previous FAQ.
  287.  
  288. Long answer: In C++, member fns have an implicit parameter which points to the
  289. object (the "this" ptr inside the member fn).  Normal C fns can be thought of
  290. as having a different calling convention from member fns, so the types of their
  291. ptrs (ptr-to-member-fn vs ptr-to-fn) are different and incompatible.  C++
  292. introduces a new type of ptr, called a ptr-to-member, which can only be invoked
  293. by providing an object (see ARM 5.5).
  294.  
  295. NOTE: do NOT attempt to "cast" a ptr-to-mem-fn into a ptr-to-fn; the result is
  296. undefined and probably disastrous.  E.g., a ptr-to- member-fn is NOT required
  297. to contain the machine addr of the appropriate fn (see ARM, 8.1.2c, p.158).  As
  298. was said in the last example, if you have a ptr to a regular C fn, use either a
  299. top-level (non-member) fn, or a "static" (class) member fn.
  300.  
  301. ==============================================================================
  302.  
  303. Q108: How do I declare an array of pointers to member functions?
  304.  
  305. Keep your sanity with "typedef".
  306.  
  307.     class Fred {
  308.     public:
  309.       int f(char x, float y);
  310.       int g(char x, float y);
  311.       int h(char x, float y);
  312.       int i(char x, float y);
  313.       //...
  314.     };
  315.  
  316.     typedef  int (Fred::*FredPtr)(char x, float y);
  317.  
  318. Here's the array of pointers to member functions:
  319.  
  320.     FredPtr a[4] = { &Fred::f, &Fred::g, &Fred::h, &Fred::i };
  321.  
  322. To call one of the member functions on object "fred":
  323.  
  324.     void userCode(Fred& fred, int methodNum, char x, float y)
  325.     {
  326.       //assume "methodNum" is between 0 and 3 inclusive
  327.       (fred.*a[methodNum])(x, y);
  328.     }
  329.  
  330. You can make the call somewhat clearer using a #define:
  331.  
  332.     #define  callMethod(object,ptrToMethod)   ((object).*(ptrToMethod))
  333.     callMethod(fred, a[methodNum]) (x, y);
  334.  
  335. ==============================================================================
  336. SECTION 19: Container classes and templates
  337. ==============================================================================
  338.  
  339. Q109: How can I insert/access/change elements from a linked
  340.    list/hashtable/etc?
  341.  
  342. I'll use an "inserting into a linked list" as a prototypical example.  It's easy
  343. to allow insertion at the head and tail of the list, but limiting ourselves to
  344. these would produce a library that is too weak (a weak library is almost worse
  345. than no library).
  346.  
  347. This answer will be a lot to swallow for novice C++'ers, so I'll give a couple
  348. of options.  The first option is easiest; the second and third are better.
  349.  
  350. [1] Empower the "List" with a "current location," and methods such as
  351. advance(), backup(), atEnd(), atBegin(), getCurrElem(), setCurrElem(Elem),
  352. insertElem(Elem), and removeElem().  Although this works in small examples, the
  353. notion of "a" current position makes it difficult to access elements at two or
  354. more positions within the List (e.g., "for all pairs x,y do the following...").
  355.  
  356. [2] Remove the above methods from the List itself, and move them to a separate
  357. class, "ListPosition."  ListPosition would act as a "current position" within a
  358. List.  This allows multiple positions within the same List.  ListPosition would
  359. be a friend of List, so List can hide its innards from the outside world (else
  360. the innards of List would have to be publicized via public methods in List).
  361. Note: ListPosition can use operator overloading for things like advance() and
  362. backup(), since operator overloading is syntactic sugar for normal methods.
  363.  
  364. [3] Consider the entire iteration as an atomic event, and create a class
  365. template to embodies this event.  This enhances performance by allowing the
  366. public access methods (which may be virtual fns) to be avoided during the inner
  367. loop.  Unfortunately you get extra object code in the application, since
  368. templates gain speed by duplicating code.  For more, see [Koenig, "Templates as
  369. interfaces," JOOP, 4, 5 (Sept 91)], and [Stroustrup, "The C++ Programming
  370. Language Second Edition," under "Comparator"].
  371.  
  372. ==============================================================================
  373.  
  374. Q110: What's the idea behind "templates"?
  375.  
  376. A template is a cookie-cutter that specifies how to cut cookies that all look
  377. pretty much the same (although the cookies can be made of various kinds of
  378. dough, they'll all have the same basic shape).  In the same way, a class
  379. template is a cookie cutter to description of how to build a family of classes
  380. that all look basically the same, and a function template describes how to
  381. build a family of similar looking functions.
  382.  
  383. Class templates are often used to build type safe containers (although this
  384. only scratches the surface for how they can be used).
  385.  
  386. ==============================================================================
  387.  
  388. Q111: What's the syntax / semantics for a "function template"?
  389.  
  390. Consider this function that swaps its two integer arguments:
  391.  
  392.     void swap(int& x, int& y)
  393.     {
  394.       int tmp = x;
  395.       x = y;
  396.       y = tmp;
  397.     }
  398.  
  399. If we also had to swap floats, longs, Strings, Sets, and FileSystems, we'd get
  400. pretty tired of coding lines that look almost identical except for the type.
  401. Mindless repetition is an ideal job for a computer, hence a function template:
  402.  
  403.     template<class T>
  404.     void swap(T& x, T& y)
  405.     {
  406.       T tmp = x;
  407.       x = y;
  408.       y = tmp;
  409.     }
  410.  
  411. Every time we used "swap()" with a given pair of types, the compiler will go to
  412. the above definition and will create yet another "template function" as an
  413. instantiation of the above.  E.g.,
  414.  
  415.     main()
  416.     {
  417.       int    i,j;  /*...*/  swap(i,j);  //instantiates a swap for "int"
  418.       float  a,b;  /*...*/  swap(a,b);  //instantiates a swap for "float"
  419.       char   c,d;  /*...*/  swap(c,d);  //instantiates a swap for "char"
  420.       String s,t;  /*...*/  swap(s,t);  //instantiates a swap for "String"
  421.     }
  422.  
  423. (note: a "template function" is the instantiation of a "function template").
  424.  
  425. ==============================================================================
  426.  
  427. Q112: What's the syntax / semantics for a "class template"?
  428.  
  429. Consider a container class of that acts like an array of integers:
  430.  
  431.     //this would go into a header file such as "Array.h"
  432.     class Array {
  433.     public:
  434.       Array(int len=10)                  : len_(len), data_(new int[len]){}
  435.      ~Array()                            { delete [] data_; }
  436.       int len() const                    { return len_;     }
  437.       const int& operator[](int i) const { data_[check(i)]; }
  438.             int& operator[](int i)       { data_[check(i)]; }
  439.       Array(const Array&);
  440.       Array& operator= (const Array&);
  441.     private:
  442.       int  len_;
  443.       int* data_;
  444.       int  check(int i) const
  445.         { if (i < 0 || i >= len_) throw BoundsViol("Array", i, len_);
  446.           return i; }
  447.     };
  448.  
  449. Just as with "swap()" above, repeating the above over and over for Array of
  450. float, of char, of String, of Array-of-String, etc, will become tedious.
  451.  
  452.     //this would go into a header file such as "Array.h"
  453.     template<class T>
  454.     class Array {
  455.     public:
  456.       Array(int len=10)                : len_(len), data_(new T[len]) { }
  457.      ~Array()                          { delete [] data_; }
  458.       int len() const                  { return len_;     }
  459.       const T& operator[](int i) const { data_[check(i)]; }
  460.             T& operator[](int i)       { data_[check(i)]; }
  461.       Array(const Array<T>&);
  462.       Array& operator= (const Array<T>&);
  463.     private:
  464.       int len_;
  465.       T*  data_;
  466.       int check(int i) const
  467.         { if (i < 0 || i >= len_) throw BoundsViol("Array", i, len_);
  468.           return i; }
  469.     };
  470.  
  471. Unlike template functions, template classes (instantiations of class templates)
  472. need to be explicit about the parameters over which they are instantiating:
  473.  
  474.     main()
  475.     {
  476.       Array<int>           ai;
  477.       Array<float>         af;
  478.       Array<char*>         ac;
  479.       Array<String>        as;
  480.       Array< Array<int> >  aai;
  481.     }              // ^^^-- note the space; do NOT use "Array<Array<int>>"
  482.                    //       (the compiler sees ">>" as a single token).
  483.  
  484. ==============================================================================
  485.  
  486. Q113: What is a "parameterized type"?
  487.  
  488. Another way to say, "class templates."
  489.  
  490. A parameterized type is a type that is parameterized over another type or some
  491. value.  List<int> is a type ("List") parameterized over another type ("int").
  492.  
  493. ==============================================================================
  494.  
  495. Q114: What is "genericity"?
  496.  
  497. Yet another way to say, "class templates."
  498.  
  499. Not to be confused with "generality" (which just means avoiding solutions which
  500. are overly specific), "genericity" means class templates.
  501.  
  502. ==============================================================================
  503. SECTION 20: Nuances of particular implementations
  504. ==============================================================================
  505.  
  506. Q115: GNU C++ (g++) produces big executables for tiny programs; Why?
  507.  
  508. libg++ (the library used by g++) was probably compiled with debug info (-g).
  509. On some machines, recompiling libg++ without debugging can save lots of disk
  510. space (~1 Meg; the down-side: you'll be unable to trace into libg++ calls).
  511. Merely "strip"ping the executable doesn't reclaim as much as recompiling
  512. without -g followed by subsequent "strip"ping the resultant "a.out"s.
  513.  
  514. Use "size a.out" to see how big the program code and data segments really are,
  515. rather than "ls -s a.out" which includes the symbol table.
  516.  
  517. ==============================================================================
  518.  
  519. Q116: Is there a yacc-able C++ grammar?
  520.  
  521. Jim Roskind is the author of a yacc grammar for C++. It's roughly compatible
  522. with the portion of the language implemented by USL cfront 2.0 (no templates,
  523. no exceptions, no run-time-type-identification).  Jim's grammar deviates from
  524. C++ in a couple of minor-but-subtle ways.
  525.  
  526. The grammar can be accessed by anonymous ftp from the following sites:
  527.  * ics.uci.edu (128.195.1.1) in "gnu/c++grammar2.0.tar.Z".
  528.  * mach1.npac.syr.edu (128.230.7.14) in "pub/C++/c++grammar2.0.tar.Z".
  529.  
  530. ==============================================================================
  531.  
  532. Q117: What is C++ 1.2?  2.0?  2.1?  3.0?
  533.  
  534. These are not versions of the language, but rather versions of cfront, which
  535. was the original C++ translator implemented by AT&T.  It has become generally
  536. accepted to use these version numbers as if they were versions of the language
  537. itself.
  538.  
  539. *VERY* roughly speaking, these are the major features:
  540.  * 2.0 includes multiple/virtual inheritance and pure virtual functions.
  541.  * 2.1 includes semi-nested classes and "delete [] ptr_to_array."
  542.  * 3.0 includes fully-nested classes, templates and "i++" vs "++i."
  543.  * 4.0 will include exceptions.
  544.  
  545. ==============================================================================
  546. SECTION 21: Miscellaneous technical and environmental issues
  547. ==============================================================================
  548. SUBSECTION 21A: Miscellaneous technical issues:
  549. ==============================================================================
  550.  
  551. Q118: Why are classes with static data members getting linker errors?
  552.  
  553. Static data members must be explicitly defined in exactly one module.  E.g.,
  554.  
  555.     class Fred {
  556.     public:
  557.       //...
  558.     private:
  559.       static int i_;  //declares static data member "Fred::i_"
  560.       //...
  561.     };
  562.  
  563. The linker will holler at you ("Fred::i_ is not defined") unless you define (as
  564. opposed to declare) "Fred::i_" in (exactly) one of your source files:
  565.  
  566.     int Fred::i_ = some_expression_evaluating_to_an_int;
  567. or:
  568.     int Fred::i_;
  569.  
  570. The usual place to define static data members of class "Fred" is file "Fred.C"
  571. (or "Fred.cpp", etc; whatever filename extension you use).
  572.  
  573. ==============================================================================
  574.  
  575. Q119: What's the difference between the keywords struct and class?
  576.  
  577. The members and base classes of a struct are public by default, while in class,
  578. they default to private.  Note: you should make your base classes EXPLICITLY
  579. public, private, or protected, rather than relying on the defaults.
  580.  
  581. "struct" and "class" are otherwise functionally equivalent.
  582.  
  583. ==============================================================================
  584.  
  585. Q120: Why can't I overload a function by its return type?
  586.  
  587. If you declare both "char f()" and "float f()", the compiler gives you an error
  588. message, since calling simply "f()" would be ambiguous.
  589.  
  590. ==============================================================================
  591.  
  592. Q121: What is "persistence"?  What is a "persistent object"?
  593.  
  594. A persistent object can live after the program which created it has stopped.
  595. Persistent objects can even outlive different versions of the creating program,
  596. can outlive the disk system, the operating system, or even the hardware on
  597. which the OS was running when they were created.
  598.  
  599. The challenge with persistent objects is to effectively store their method code
  600. out on secondary storage along with their data bits (and the data bits and
  601. method code of all member objects, and of all their member objects and base
  602. classes, etc).  This is non-trivial when you have to do it yourself.  In C++,
  603. you have to do it yourself.  C++/OO databases can help hide the mechanism for
  604. all this.
  605.  
  606. ==============================================================================
  607. SUBSECTION 21B: Miscellaneous environmental issues:
  608. ==============================================================================
  609.  
  610. Q122: Is there a TeX or LaTeX macro that fixes the spacing on "C++"?
  611.  
  612. Yes, here are two:
  613.  
  614. \def\CC{C\raise.22ex\hbox{{\footnotesize +}}\raise.22ex\hbox{\footnotesize +}}
  615.  
  616. \def\CC{{C\hspace{-.05em}\raisebox{.4ex}{\tiny\bf ++}}}
  617.  
  618. ==============================================================================
  619.  
  620. Q123: Where can I access C++2LaTeX, a LaTeX pretty printer for C++ source?
  621.  
  622. Here are a few ftp locations:
  623.  
  624. Host aix370.rrz.uni-koeln.de   (134.95.80.1) Last updated 15:41 26 Apr 1991
  625.     Location: /tex
  626.       FILE      rw-rw-r--     59855  May  5  1990   C++2LaTeX-1.1.tar.Z
  627. Host utsun.s.u-tokyo.ac.jp   (133.11.11.11) Last updated 05:06 20 Apr 1991
  628.     Location: /TeX/macros
  629.       FILE      rw-r--r--     59855  Mar  4 08:16   C++2LaTeX-1.1.tar.Z
  630. Host nuri.inria.fr   (128.93.1.26) Last updated 05:23  9 Apr 1991
  631.     Location: /TeX/tools
  632.       FILE      rw-rw-r--     59855  Oct 23 16:05   C++2LaTeX-1.1.tar.Z
  633. Host iamsun.unibe.ch   (130.92.64.10) Last updated 05:06  4 Apr 1991
  634.     Location: /TeX
  635.       FILE      rw-r--r--     59855  Apr 25  1990   C++2LaTeX-1.1.tar.Z
  636. Host iamsun.unibe.ch   (130.92.64.10) Last updated 05:06  4 Apr 1991
  637.     Location: /TeX
  638.       FILE      rw-r--r--     51737  Apr 30  1990
  639.       C++2LaTeX-1.1-PL1.tar.Z
  640. Host tupac-amaru.informatik.rwth-aachen.de   (192.35.229.9) Last updated 05:07 18 Apr 1991
  641.     Location: /pub/textproc/TeX
  642.       FILE      rw-r--r--     72957  Oct 25 13:51  C++2LaTeX-1.1-PL4.tar.Z
  643. Host wuarchive.wustl.edu   (128.252.135.4) Last updated 23:25 30 Apr 1991
  644.     Location: /packages/tex/tex/192.35.229.9/textproc/TeX
  645.       FILE      rw-rw-r--     49104  Apr 10  1990   C++2LaTeX-PL2.tar.Z
  646.       FILE      rw-rw-r--     25835  Apr 10  1990   C++2LaTeX.tar.Z
  647. Host tupac-amaru.informatik.rwth-aachen.de   (192.35.229.9) Last updated 05:07 18 Apr 1991
  648.     Location: /pub/textproc/TeX
  649.       FILE rw-r--r-- 74015  Mar 22 16:23 C++2LaTeX-1.1-PL5.tar.Z
  650.     Location: /pub
  651.       FILE rw-r--r-- 74015  Mar 22 16:23 C++2LaTeX-1.1-PL5.tar.Z
  652. Host sol.cs.ruu.nl   (131.211.80.5) Last updated 05:10 15 Apr 1991
  653.     Location: /TEX/TOOLS
  654.       FILE      rw-r--r--     74015  Apr  4 21:02x   C++2LaTeX-1.1-PL5.tar.Z
  655. Host tupac-amaru.informatik.rwth-aachen.de (192.35.229.9) Last updated 05:07 18 Apr 1991
  656.     Location: /pub/textproc/TeX
  657.       FILE      rw-r--r--      4792  Sep 11  1990 C++2LaTeX-1.1-patch#1
  658.       FILE      rw-r--r--      2385  Sep 11  1990 C++2LaTeX-1.1-patch#2
  659.       FILE      rw-r--r--      5069  Sep 11  1990 C++2LaTeX-1.1-patch#3
  660.       FILE      rw-r--r--      1587  Oct 25 13:58 C++2LaTeX-1.1-patch#4
  661.       FILE      rw-r--r--      8869  Mar 22 16:23 C++2LaTeX-1.1-patch#5
  662.       FILE      rw-r--r--      1869  Mar 22 16:23 C++2LaTeX.README
  663. Host rusmv1.rus.uni-stuttgart.de   (129.69.1.12) Last updated 05:13 13 Apr 1991
  664.     Location: /soft/tex/utilities
  665.       FILE      rw-rw-r--    163840  Jul 16  1990   C++2LaTeX-1.1.tar
  666.  
  667. ==============================================================================
  668.  
  669. Q124: Where can I access "tgrind," a pretty printer for C++/C/etc source?
  670.  
  671. "tgrind" reads a C++ source file, and spits out something that looks pretty on
  672. most Unix printers.  It usually comes with the public distribution of TeX and
  673. LaTeX; look in the directory: "...tex82/contrib/van/tgrind".  A more up-to-date
  674. version of tgrind by Jerry Leichter can be found on: venus.ycc.yale.edu in
  675. [.TGRIND].
  676.  
  677. ==============================================================================
  678.  
  679. Q125: Is there a C++-mode for GNU emacs?  If so, where can I get it?
  680.  
  681. Yes, there is a C++-mode for GNU emacs.  You can get it via:
  682.  
  683. c++-mode-2 (1.0)  87-12-08
  684.      Bruce Eckel,Thomas Keffer, <eckel@beluga.ocean.washington.edu,uw-beaver!beluga!eckel,keffer@sperm.ocean.washington.edu>
  685.      archive.cis.ohio-state.edu:/pub/gnu/emacs/elisp-archive/as-is/c++-mode-2.el.Z
  686.  
  687.      Another C++ major mode.
  688. c++-mode      89-11-07
  689.      Dave Detlefs, et al, <dld@cs.cmu.edu>
  690.      archive.cis.ohio-state.edu:/pub/gnu/emacs/elisp-archive/modes/c++-mode.el.Z
  691.  
  692.      C++ major mode.
  693. c++          90-02-01
  694.      David Detlefs, Stewart Clamen, <dld@f.gp.cs.cmu.edu,clamen@cs.cmu.edu>
  695.      archive.cis.ohio-state.edu:/pub/gnu/emacs/elisp-archive/modes/c++.el.Z
  696.      C++ code editing commands for Emacs
  697.  
  698. c-support (46)      89-11-04
  699.      Lynn Slater, <lrs@indetech.com>
  700.      archive.cis.ohio-state.edu:/pub/gnu/emacs/elisp-archive/misc/c-support.el.Z
  701.      Partial support for team C/C++ development.
  702.  
  703. ==============================================================================
  704.  
  705. Q126: Where can I get OS-specific FAQs answered (e.g.,BC++,DOS,Windows,etc)?
  706.  
  707. see comp.os.msdos.programmer, BC++ and Zortech mailing lists, BC++ and
  708.    Zortech bug lists, comp.windows.ms.programmer, comp.unix.programmer, etc.
  709.  
  710. You can subscribe to the BC++ mailing list by sending email to:
  711. |    To: listserv@ucf1vm.cc.ucf.edu   <---or LISTSERV@UCF1VM.BITNET
  712. |    Subject: SUB TCPLUS-L
  713. |    Reply-to: you@your.email.addr    <---i.e., put your return address here
  714.  
  715. The BC++ bug report is available via anonymous ftp from sun.soe.clarkson.edu
  716. [128.153.12.3] from the file ~ftp/pub/Turbo-C++/bug-report
  717. (also, I post it on comp.lang.c++ on the first each month).
  718.  
  719. Relevant email addresses:
  720.     ztc-list@zortech.com          General requests and discussion
  721.     ztc-list-request@zortech.com  Requests to be added to ztc-list
  722.     ztc-bugs@zortech.com          For _short_ bug reports
  723.  
  724. ==============================================================================
  725.  
  726. Q127: Why does my DOS C++ program says "Sorry: floating point code not
  727.    linked"?
  728.  
  729. The compiler attempts to save space in the executable by not including the
  730. float-to-string format conversion routines unless they are necessary, but
  731. sometimes it guesses wrong, and gives you the above error message.  You can fix
  732. this by (1) using <iostream.h> instead of <stdio.h>, or (2) by including the
  733. following function somewhere in your compilation (but don't call it!):
  734.  
  735.     static void dummyfloat(float *x) { float y; dummyfloat(&y); }
  736.  
  737. See FAQ on stream I/O for more reasons to use <iostream.h> vs <stdio.h>.
  738.  
  739. ==============================================================================
  740.  
  741. --
  742. Marshall Cline
  743. --
  744. Marshall P. Cline, Ph.D. / Paradigm Shift Inc / PO Box 5108 / Potsdam NY 13676
  745. cline@sun.soe.clarkson.edu / 315-353-6100 / FAX: 315-353-6110
  746.